package com.asm.controller.api;

import com.asm.dto.PageResult;
import com.asm.dto.Result;
import com.asm.service.CommunityTagService;
import com.asm.vo.sys.CommunityTagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * @author tanzujie
 */
@RestController
public class CommunityTagController {
    @Autowired
    private CommunityTagService communitytagService;

    /**
     * 分页查询所有小区标签
     *
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/communitytags")
    public ResponseEntity<PageResult<CommunityTagVo>> getAllCommunityTags(Integer pageNumber, Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findAllCommunityTags(pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据Id获取小区标签
     *
     * @param id
     * @return
     */
    @GetMapping("/communitytag/{id}")
    public ResponseEntity<Result<CommunityTagVo>> getCommunityTagById(@PathVariable("id") Long id) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagById(id)), HttpStatus.OK);
    }

    /**
     * 根据小区标签类型分页查询小区标签
     *
     * @param type
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/communitytags/type/{type}")
    public ResponseEntity<PageResult<CommunityTagVo>> getCommunityTagsByType(@PathVariable("type") String type, Integer pageNumber, Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagBytagType(type, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据小区标签大小分页查询小区标签
     *
     * @param communityid
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/communitytags/communityid/{communityid}")
    public ResponseEntity<PageResult<CommunityTagVo>> getCommunityTagsBySize(@PathVariable("communityid") Long communityid, Integer pageNumber, Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagByCommunityId(communityid, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 增加小区标签
     *
     * @param communitytagVo
     * @return
     */
    @PostMapping("/communitytag/add")
    public ResponseEntity<Result> addCommunityTag(@RequestBody CommunityTagVo communitytagVo) {
        communitytagService.addCommunityTag(communitytagVo);
        return new ResponseEntity(new Result().ok("add success"), HttpStatus.OK);
    }

    /**
     * 更新小区标签
     *
     * @param communitytagVo
     * @return
     */
    @PutMapping("/communitytag/update")
    public ResponseEntity<Result> updateCommunityTag(@RequestBody CommunityTagVo communitytagVo) {
        communitytagService.updateCommunityTag(communitytagVo);
        return new ResponseEntity(new Result().ok("update success"), HttpStatus.OK);
    }

    /**
     * 根据Id删除小区标签
     *
     * @param id
     * @return
     */
    @DeleteMapping("/communitytag/delete/{id}")
    public ResponseEntity<Result> deleteCommunityTag(@PathVariable("id") Long id) {
        communitytagService.deleteCommunityTag(id);
        return new ResponseEntity(new Result().ok("delete success"), HttpStatus.OK);
    }
}
